package com.kingint.web.portal.base.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.kingint.common.unitedresult.K;
import com.kingint.mbg.bas.entity.BasRoom;
import com.kingint.web.portal.base.service.RoomService;
import com.kingint.web.sys.service.UmsMemberService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @描述：房间信息控制类
 * @作者: wxh
 * @日期: 2020-12-23
 */
@RestController
@RequestMapping("/Room")
@Api(value = "BasRoomController", description = "房间信息")
@CrossOrigin
public class RoomController {

    @Autowired
    public RoomService basRoomService;
    @Autowired
    public UmsMemberService umsMemberService;


    @ApiOperation(value = "根据房间信息名称分页获取房间信息列表")
    @GetMapping("/list")
    public Object getList(BasRoom basRoom) {
        basRoom.setHotelId(umsMemberService.getUserHotel());
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("hotel_id", basRoom.getHotelId());
        if (!StringUtils.isEmpty(basRoom.getRoomNum())) {
            queryWrapper.eq("room_num", basRoom.getRoomNum());
        } else if (!StringUtils.isEmpty(basRoom.getFloorId())) {
            queryWrapper.eq("floor_id", basRoom.getFloorId());
        }
        List<BasRoom> list = basRoomService.list(queryWrapper);
        return K.ok().data(list);
    }

    @ApiOperation(value = "根据编号查询房间信息信息")
    @GetMapping("/{id}")
    public Object getItem(@PathVariable("id") Long id) {
        BasRoom basRoom = basRoomService.getById(id);
        return K.ok().data(basRoom);
    }
}